import cgi
import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')

from django.utils import simplejson
from google.appengine.ext import webapp

from instancetier import GetInstanceTierHandler

class GetTierListHandler(webapp.RequestHandler):
  def post(self, instance=""):
    #TODO: Placeholder response
    #TODO: Make sure to strip the opening '/'
    
    tierList = {}
    tierList["tiers"] = ["7.0", "8.0", "9.0", "9.5", "10.0", "10.5"]
    
    # Only thing in the post data object we care about is the command ID.
    tierList["commandID"] = simplejson.loads( self.request.get("data") )["commandID"]
    
    # User may or may not have passed in an instance
    if(instance):
      tierList["instanceTier"] = GetInstanceTierHandler.instanceTier(instance)
    
    self.response.headers["Content-Type"] = "text/plain"
    self.response.out.write( simplejson.dumps(tierList) )
    
  def get(self, instance=""):
    self.response.headers["Content-Type"] = "text/plain"
    self.response.out.write("Got it.")